#!/usr/bin/perl

# ApsalarRunner.py will add the necessary libraries to the xcode project
$installPath = $ARGV[1];
$currDir = $ARGV[0];
$find = "_SOOM@#";
$replace = " ";
$find = quotemeta $find;
my $old_installPath = $installPath;
$installPath =~ s/$find/$replace/g;
$currDir =~ s/$find/$replace/g;
chomp $currDir; 
chomp $installPath;

`python2.6 \'$currDir/Soomla/Editor/build-tools/SoomlaRunner.py\' \'$old_installPath\'`;

$old = "$installPath/Unity-iPhone.xcodeproj/project.pbxproj";
$new = "$installPath/tmp.$$";
open(OLD, "< $old")         or die "can't open $old: $!";
open(NEW, "> $new")         or die "can't open $new: $!";
    # Correct typos, preserving case
while (<OLD>) {
  $line = $_;
  if( $line =~ /GCC_ENABLE_OBJC_EXCEPTIONS = NO;/){
  	$line = "GCC_ENABLE_OBJC_EXCEPTIONS = YES;";
  }
  if( $line =~ /GCC_ENABLE_CPP_EXCEPTIONS = NO;/){
  	$line = "GCC_ENABLE_CPP_EXCEPTIONS = YES;";
  }
  (print NEW $line)          or die "can't write to $new: $!";
}
close(OLD)                  or die "can't close $old: $!";
close(NEW)                  or die "can't close $new: $!";
rename($new, $old)          or die "can't rename $new to $old: $!";
